package algorithms.sorts.radix;

import algorithms.Utils;

public interface RadixSequenceAdapter<E> {

    RadixKey<E> getKey(int i);

    E get(int i);

    void set(int i, E e);

    int size();

    int maxRadixCount();

    int keyCountAt(int radix);

    static RadixSequenceAdapter<Integer> wrapIntArray(Integer[] arr) {

        return new RadixSequenceAdapter<>() {

            @Override
            public RadixKey<Integer> getKey(int i) {
                return RadixKey.wrapInt(arr[i]);
            }

            @Override
            public Integer get(int i) {
                return arr[i];
            }

            @Override
            public void set(int i, Integer integer) {
                arr[i] = integer;
            }

            @Override
            public int size() {
                return arr.length;
            }

            @Override
            public int maxRadixCount() {
                Integer max = Utils.max(arr);
                Integer min = Utils.min(arr);
                return Math.max(RadixKey.wrapInt(max).radixCount(), RadixKey.wrapInt(min).radixCount());
            }

            @Override
            public int keyCountAt(int radix) {
                return 19;
            }
        };
    }
}
